﻿#region header

//  ***************************************************************************
// *                                LICENSE
//  ***************************************************************************
//  * "Haplous" .NET Simple 2D Game Framework
//  * 
//  * Copyright © Jonathan Evans 2014-2014
//  * 
//  * This program is free software; you can redistribute it and/or
//  * modify it under the terms of the GNU General Public License
//  * as published by the Free Software Foundation; either version 2
//  * of the License, or (at your option) any later version.
//  * 
//  * This program is distributed in the hope that it will be useful,
//  * but WITHOUT ANY WARRANTY; without even the implied warranty of
//  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  * GNU General Public License for more details.
//  * 
//  * You should have received a copy of the GNU General Public License
//  * along with this program; if not, write to the Free Software
//  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//  * 
//  ***************************************************************************
//  * 
//  * Contact: opencollar@googlemail.com
//  * 
//  * Website: http://haplous.codeplex.com/
//  *
//  * NuGet:   http://www.nuget.org/packages/haplous/
//  *
//  * File:    Haplous/Haplous/Opacity.cs
//  *
//  ***************************************************************************

#endregion

using System;
using System.Diagnostics;

using Haplous.Core;

namespace Haplous
{
    /// <summary>
    ///     A class representing an opacity value.
    /// </summary>
    [DebuggerDisplay("Opacity: Value={Value}")]
    public class Opacity : NotifyObject, IProperty<Opacity>
    {
        /// <summary>
        ///     The current opacity of the block represented.
        /// </summary>
        private double _value = 1d;

        /// <summary>
        ///     Initializes a new instance of the <see cref="Opacity" /> class.
        /// </summary>
        public Opacity()
        {}

        /// <summary>
        ///     Initializes a new instance of the <see cref="Opacity" /> class.
        /// </summary>
        /// <param name="value">The initial value.</param>
        /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="value" /> must be between 0 and 1.</exception>
        public Opacity(double value)
        {
            if((value < 0d) || (value > 1d))
                throw new ArgumentOutOfRangeException("value", value, "'value' must be between 0 and 1.");

            _value = value;
        }

        /// <summary>
        ///     Gets or sets the opacity of this block, where 0 indicates invisible and 1 indicates fully opaque.
        /// </summary>
        /// <value>
        ///     The opacity of this block, where 0 indicates invisible and 1 indicates fully opaque.  Values outside this range
        ///     will cause an exception to be thrown.
        /// </value>
        public double Value
        {
            get { return _value; }
            set
            {
                if((value < 0d) || (value > 1d))
                    throw new ArgumentOutOfRangeException("value", value, "'value' must be between 0 and 1.");

                OnPropertyChanged("Value", ref _value, value);
            }
        }

        /// <summary>
        ///     Copies the value of the specified property object into the current property object.
        /// </summary>
        /// <param name="property">The property object from which to copy the value.</param>
        public void Copy(IProperty<Opacity> property)
        {
            Value = ((Opacity)property).Value;
        }
    }
}